<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="12" :sm="8">
            <a-form-item label="模型名称" :labelCol="{ span: 5 }" :wrapperCol="{ span: 18, offset: 1 }">
              <j-input placeholder="请输入模型名称" v-model="queryParam.topicName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="8">
            <a-form-item label="接口服务编码" :labelCol="{ span: 5 }" :wrapperCol="{ span: 18, offset: 1 }">
              <j-input placeholder="请输入接口服务编码" v-model="queryParam.serviceCode"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="8">
            <a-form-item label="存储数据表" :labelCol="{ span: 5 }" :wrapperCol="{ span: 18, offset: 1 }">
              <j-input placeholder="请输入存储数据表" v-model="queryParam.topicTable"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery">查询</a-button>
              <a-button type="primary" @click="searchResetBefore" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
          selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">取消勾选</a>
      </div>

      <a-table ref="table" size="middle" :scroll="{ x: true }" bordered rowKey="id" :columns="columns"
        :dataSource="dataSource" :pagination="ipagination" :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" class="j-table-force-nowrap"
        @change="handleTableChange">

        <span slot="topicCols" slot-scope="topicCols">
          <div style="float: left" v-for="(topic, index) in topicCols" :key="index">
            <a-tag style="font-size: 14px; margin-top: 5px" v-if="topic.isIndex === '0'" color="blue">{{
              topic.columnComment
            }}</a-tag>
          </div>
        </span>

        <span slot="serviceStatus" slot-scope="serviceStatus">
          <span :style="{ color: serviceStatus === '1' ? 'green' : 'red' }">{{
            serviceStatus === '1' ? '启用' : serviceStatus === '2' ? '停止' : '--'
          }}</span>
        </span>

        <span slot="action" slot-scope="text, record">
          <a @click="handleViewData(record)">查看数据</a>
        </span>
      </a-table>
    </div>
    <select-sc-situation-index-info-modal-new ref="modalForm" @ok="modalFormOk" />
    <DataEdit ref="dataEdit" />
  </a-card>
</template>

<script>
import { getAction, deleteAction } from '@/api/manage'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import SelectScSituationIndexInfoModalNew from './SelectScSituationIndexInfoModalNew'
import DataEdit from '@/views/data-edit/DataEdit'
export default {
  name: 'SystemScSituationIndexTopicList',
  components: {
    SelectScSituationIndexInfoModalNew,
    DataEdit
  },
  mixins: [JeecgListMixin, mixinDevice],
  data() {
    return {
      catalogId: null,
      description: '指标模型信息表管理页面',
      // 表头
      columns: [
        {
          title: '模型名称',
          align: 'center',
          dataIndex: 'topicName'
        },
        {
          title: '维度信息',
          align: 'left',
          dataIndex: 'topicCols',
          scopedSlots: { customRender: 'topicCols' }
        },
        {
          title: '存储数据表',
          align: 'center',
          dataIndex: 'topicTable'
        },
        {
          title: '接口服务编码',
          align: 'center',
          dataIndex: 'serviceCode'
        },
        {
          title: '接口服务状态',
          align: 'center',
          dataIndex: 'serviceStatus',
          scopedSlots: { customRender: 'serviceStatus' }
        },
        {
          title: '编辑人',
          align: 'center',
          dataIndex: 'createBy'
        },
        {
          title: '编辑时间',
          align: 'center',
          dataIndex: 'createTime'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 100,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/topic/config/pageTopic'
      },
      dictOptions: {},
      superFieldList: [],
      isorter: {
        column: null,
        order: null
      }
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  created() {
    this.getSuperFieldList()
  },
  methods: {
    handleViewData(record) {
      this.$refs.dataEdit.handleOpenData(record,
        {
          dataSource: record.dataSourceCode,
          serviceCode: record.serviceCode,
          tableName: record.tableName
        }
      )
    },
    searchResetBefore() {
      this.queryParam = {
        topicType: this.catalogId
      }
      this.loadData(1)
    },
    clearDataSource() {
      this.dataSource = []
      this.ipagination.total = 0
      this.ipagination.current = 1
      this.queryParam.topicType = null
      this.catalogId = null
    },
    show(catalogId) {
      this.clearDataSource()
      if (catalogId === undefined || catalogId === null || catalogId === '') {
        //
      } else {
        if (catalogId !== '0') {
          this.queryParam.topicType = catalogId
        }
        this.catalogId = catalogId
        this.loadData()
      }
    },
    getSuperFieldList() {
      const fieldList = []
      fieldList.push({ type: 'string', value: 'name', text: '指标名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'dimensionInfoVoList', text: '维度', dictCode: '' })
      fieldList.push({ type: 'string', value: 'remark', text: '描述', dictCode: '' })
      fieldList.push({ type: 'string', value: 'configId', text: '配置名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'dataSource', text: '数据源', dictCode: 'sys_data_source,name,code' })
      fieldList.push({ type: 'string', value: 'tableName', text: '表名', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tableColumn', text: '字段名', dictCode: '' })
      fieldList.push({ type: 'int', value: 'dataType', text: '数据类型', dictCode: 'column_data_type' })
      fieldList.push({ type: 'int', value: 'columnLength', text: '数据长度', dictCode: '' })
      fieldList.push({ type: 'string', value: 'scale', text: '小数精度', dictCode: '' })
      fieldList.push({ type: 'string', value: 'unit', text: '统计单位', dictCode: '' })
      fieldList.push({ type: 'int', value: 'isPercent', text: '是否率值', dictCode: 'yn' })
      fieldList.push({ type: 'string', value: 'groupType', text: '汇聚类型', dictCode: 'index_group_type' })
      // fieldList.push({ type: 'int', value: 'status', text: '状态', dictCode: '' })
      fieldList.push({ type: 'string', value: 'updateBy', text: '编辑人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'updateTime', text: '编辑时间', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
